<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css">
  <script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"daydaychen.github.io","root":"/","scheme":"Gemini","version":"7.7.2","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":true,"lazyload":true,"pangu":true,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":true,"nav":null,"activeClass":"valine"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":false},"motion":{"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="进程和线程的区别12345678import multiprocessingdef test()    passp1 &#x3D; multiprocessing.Process(target&#x3D;test)p1.start()  进程：  程序运行起来就是进程   是资源分配的单位 进程在执行过程中拥有独立的内存单元，而多个线程共享内存，从而极大地提高了程序的执行效率  线程：  线程是进">
<meta property="og:type" content="article">
<meta property="og:title" content="python进程">
<meta property="og:url" content="daydaychen.github.io/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E8%BF%9B%E7%A8%8B/index.html">
<meta property="og:site_name" content="宁静致远">
<meta property="og:description" content="进程和线程的区别12345678import multiprocessingdef test()    passp1 &#x3D; multiprocessing.Process(target&#x3D;test)p1.start()  进程：  程序运行起来就是进程   是资源分配的单位 进程在执行过程中拥有独立的内存单元，而多个线程共享内存，从而极大地提高了程序的执行效率  线程：  线程是进">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-03-06T06:15:48.709Z">
<meta property="article:modified_time" content="2020-03-06T06:15:48.709Z">
<meta property="article:author" content="CT">
<meta property="article:tag" content="python">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="daydaychen.github.io/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E8%BF%9B%E7%A8%8B/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>python进程 | 宁静致远</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">宁静致远</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">this is a subtitle.</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="daydaychen.github.io/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E8%BF%9B%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="CT">
      <meta itemprop="description" content="this is a desc.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="宁静致远">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          python进程
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-06 14:15:48" itemprop="dateCreated datePublished" datetime="2020-03-06T14:15:48+08:00">2020-03-06</time>
            </span>

          
            <span id="/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E8%BF%9B%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="python进程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E8%BF%9B%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E8%BF%9B%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h4 id="进程和线程的区别"><a href="#进程和线程的区别" class="headerlink" title="进程和线程的区别"></a>进程和线程的区别</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">import multiprocessing</span><br><span class="line"></span><br><span class="line">def test()</span><br><span class="line">    pass</span><br><span class="line"></span><br><span class="line">p1 &#x3D; multiprocessing.Process(target&#x3D;test)</span><br><span class="line"></span><br><span class="line">p1.start()</span><br></pre></td></tr></table></figure>

<p><strong>进程：</strong></p>
<ol>
<li>程序运行起来就是进程  </li>
<li>是资源分配的单位</li>
<li>进程在执行过程中拥有独立的内存单元，而多个线程共享内存，从而极大地提高了程序的执行效率</li>
</ol>
<p><strong>线程：</strong></p>
<ol>
<li>线程是进程中执行具体操作的个体 </li>
<li>是任务调度的单位</li>
<li>线程运行开销小，但不利于资源的管理和保护，进程正相反</li>
<li>线程不能够独立执行，必须依存在进程中</li>
<li>可以将进程理解为工厂中的一条流水线，而其中的线程就是这个流水线上的工人</li>
</ol>
<h4 id="通过队列完成进程间的通信"><a href="#通过队列完成进程间的通信" class="headerlink" title="通过队列完成进程间的通信"></a>通过队列完成进程间的通信</h4><p>队列：先进先出</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">from multiprocessing import Queue</span><br><span class="line"></span><br><span class="line"># 初始化一个Queue对象</span><br><span class="line">q&#x3D;Queue(3)          # 最多可几收三条put信息</span><br><span class="line"></span><br><span class="line"># 往队列中放数据</span><br><span class="line">q.put(&#39;message1&#39;)   # 数据类型任意</span><br><span class="line">q.put(&#39;message2&#39;)</span><br><span class="line">q.put(&#39;message3&#39;)</span><br><span class="line">q.put(&#39;message4&#39;)   # 会阻塞，因为队列满了</span><br><span class="line"></span><br><span class="line"># 判断队列状态</span><br><span class="line">q.full()     # False 表示队列不满</span><br><span class="line">q.full()     # True 表示队列满了</span><br><span class="line">q.empty()    # False 表示队列不为空</span><br><span class="line">q.empty()    # True 表示队列为空</span><br><span class="line"></span><br><span class="line"># 从队列取数据</span><br><span class="line">q.get()             # 先进后出</span><br><span class="line">q.get_nowait()      # 不等待取数据</span><br></pre></td></tr></table></figure>

<p><strong>作用：</strong><br>通过队列解耦合，进程A下载数据，进程B处理数据，互不影响</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">import multiprocessing</span><br><span class="line"></span><br><span class="line">def download_from_web():</span><br><span class="line">    # 模拟从网上下载数据</span><br><span class="line">    data &#x3D;&#x3D; [11, 22, 33, 44]</span><br><span class="line"></span><br><span class="line">    # 像队列中写入数据</span><br><span class="line">    from temp in data:</span><br><span class="line">        q.put()</span><br><span class="line">        </span><br><span class="line">    print(&quot;下载器已经下载完了数据并且存入到队列中。&quot;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def analysis_data():</span><br><span class="line">    &#39;&#39;&#39;数据处理&#39;&#39;&#39;</span><br><span class="line">    waitting_analysis_data &#x3D; list()</span><br><span class="line">    # 从队列中取数据</span><br><span class="line">    while True:</span><br><span class="line">        data &#x3D; q.get()</span><br><span class="line">        waitting_analysis_data.append(data)</span><br><span class="line">        </span><br><span class="line">        if q.empty():</span><br><span class="line">            break</span><br><span class="line"></span><br><span class="line">    # 模拟数据处理</span><br><span class="line">    print(waitting_analysis_data)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def main()</span><br><span class="line">    # 1. 创建一个队列</span><br><span class="line">    q &#x3D; multiprocessing.Queue()</span><br><span class="line">    </span><br><span class="line">    # 2. 创建多个进程，将队列的应用当作实参进行传递到里面</span><br><span class="line">    p1 &#x3D; multiprocessing.Process(target&#x3D;download_from_web, args&#x3D;(q,))</span><br><span class="line">    p2 &#x3D; multiprocessing.Process(target&#x3D;analysis_data， argd&#x3D;(q,))</span><br><span class="line"></span><br><span class="line">    p1.start()</span><br><span class="line">    p2.start()</span><br><span class="line">    </span><br><span class="line">if __name__ &#x3D;&#x3D; &quot;__main__&quot;:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>

<h4 id="进程池Pool"><a href="#进程池Pool" class="headerlink" title="进程池Pool"></a>进程池Pool</h4><p>重复利用进程池中的进程<br>进程数过多时，采用进程池减少进程的数量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">from multiprocessing import Pool</span><br><span class="line"></span><br><span class="line">po &#x3D; Pool(3)    # 定义一个进程池，最大进程数为3</span><br><span class="line">po.apply_async(worker,(1,))  #要调用的目标，(传递给目标的参数元组,))</span><br><span class="line">po.close()      # 关闭进程池</span><br><span class="line">po.jion()       # 等待po中所有子进程完成，必须放在close()前面</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">from multiprocessing import Pool</span><br><span class="line">import os, time, random</span><br><span class="line"></span><br><span class="line">def worker(msg):</span><br><span class="line">    t_start &#x3D; time.time()</span><br><span class="line">    print(&quot;%s开始执行，进程号为%d&quot; % (msg,os.getpid()))</span><br><span class="line">    # random.random() 随机生成0-1之间的浮点数</span><br><span class="line">    time.sleep(random.random()*2)</span><br><span class="line">    t_stop &#x3D; time.time()</span><br><span class="line">    print(msg,&quot;执行完毕，好事%0.2f&quot; % (t_stop-t_start))</span><br><span class="line">    </span><br><span class="line">po &#x3D; Pool(3)        # 定义一个进程池，最大进程数3</span><br><span class="line">for i in range(0,10):</span><br><span class="line">    # Pool().apply_async(要调用的目标，(传递给目标的参数元组，))</span><br><span class="line">    # 每次循环将会用空闲出来的子进程去调用目标</span><br><span class="line">    po.apply_async(worker,(i,))</span><br><span class="line">    </span><br><span class="line">print(&quot;----start----&quot;)</span><br><span class="line">po.close()          # 关闭进程池，关闭后po不再接收新的请求</span><br><span class="line">po.join()           # 等待po中所有子进程执行完成，必须放在close语句之后</span><br><span class="line">print(&quot;----end----&quot;)</span><br></pre></td></tr></table></figure>

<h4 id="案例-实现copy"><a href="#案例-实现copy" class="headerlink" title="案例 实现copy"></a>案例 实现copy</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">import multiprocessing</span><br><span class="line">import os</span><br><span class="line"></span><br><span class="line">def copy_file(q, file_name, old_folder_name, new_folder_name):</span><br><span class="line">    &#39;&#39;&#39;完成文件的复制&#39;&#39;&#39;</span><br><span class="line">    old_f &#x3D; open(old_folder_name + &quot;&#x2F;&quot; + file_name, &quot;rb&quot;)</span><br><span class="line">    content &#x3D; old_f.read()</span><br><span class="line">    old_f.close()</span><br><span class="line">    </span><br><span class="line">    new_f &#x3D; open(new_folder_name + &quot;&#x2F;&quot; + file_name, &quot;wb&quot;)</span><br><span class="line">    content &#x3D; new_f.write()</span><br><span class="line">    new_f.close()</span><br><span class="line">    </span><br><span class="line">    # 如果拷贝完了文件，那么就向队列中写入一个消息表示已经完成</span><br><span class="line">    q.put(file_name)</span><br><span class="line">    </span><br><span class="line">def main():</span><br><span class="line">    # 1. 获取用户要copy的文件夹的名字</span><br><span class="line">    old_folder_name &#x3D; input(&quot;请输入要copy的文件夹的名字：&quot;)</span><br><span class="line">    </span><br><span class="line">    # 2. 创建一个新的文件夹</span><br><span class="line">    try:</span><br><span class="line">        new_folder_name &#x3D; old_folder_name + &quot;[复件]&quot;</span><br><span class="line">        os.mkdir(new_folder_name)</span><br><span class="line">    except:</span><br><span class="line">        pass</span><br><span class="line"></span><br><span class="line">    # 3. 获取文件夹的所有的待copy的文件名字 listdir()</span><br><span class="line">    file_names &#x3D; os.listdir(old_folder_name)</span><br><span class="line">    # print(file_names)</span><br><span class="line">    </span><br><span class="line">    # 4. 创建进程池 主进程负责往进程池添加 进程池负责拷贝</span><br><span class="line">    po &#x3D; multiprocessing.Pool(5)</span><br><span class="line">    </span><br><span class="line">    # 5. 创建一个队列</span><br><span class="line">    q &#x3D; multiprocessing.Manager().Queue()</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    # 6. 向进程池中添加copy文件的任务</span><br><span class="line">    for file_name in file_names:</span><br><span class="line">        po.apply_async(q, copy_file,args&#x3D;(file_name, old_folder_name. new_folder_name)</span><br><span class="line">    # 进程池中的进程出错时不会抛出异常。</span><br><span class="line">    po.close()</span><br><span class="line">    # po.join()</span><br><span class="line">    all_file_num &#x3D; len(file_names) # 所有文件的个数</span><br><span class="line">    copy_ok_num &#x3D; 0</span><br><span class="line">    while True:</span><br><span class="line">        file_name &#x3D; q.get()</span><br><span class="line">        # print(&quot;已经完成copy： %s&quot; % file_name)</span><br><span class="line">        copy_ok_num +&#x3D; 1</span><br><span class="line">        print(&quot;\r拷贝的进度为：%.2f%%&quot; % (copy_on_num*100 &#x2F;&#x2F; all_file_num),end&#x3D;&quot;&quot;)</span><br><span class="line">        if copy_ok_num &gt;&#x3D; all_file_num:</span><br><span class="line">            break</span><br><span class="line">        </span><br><span class="line">        print()</span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">if __name__ &#x3D;&#x3D; &quot;__main__&quot;:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/python/" rel="tag"># python</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/03/06/02-%E5%A4%9A%E4%BB%BB%E5%8A%A1-%E7%BA%BF%E7%A8%8B/" rel="prev" title="python线程">
      <i class="fa fa-chevron-left"></i> python线程
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/03/06/01-%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" rel="next" title="正则表达式">
      正则表达式 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#进程和线程的区别"><span class="nav-number">1.</span> <span class="nav-text">进程和线程的区别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#通过队列完成进程间的通信"><span class="nav-number">2.</span> <span class="nav-text">通过队列完成进程间的通信</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#进程池Pool"><span class="nav-number">3.</span> <span class="nav-text">进程池Pool</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#案例-实现copy"><span class="nav-number">4.</span> <span class="nav-text">案例 实现copy</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="CT"
      src="/images/avatar.gif">
  <p class="site-author-name" itemprop="name">CT</p>
  <div class="site-description" itemprop="description">this is a desc.</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">16</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/daydaychen" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;daydaychen" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:ctt0120@foxmail.com" title="E-Mail → mailto:ctt0120@foxmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">CT</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.2
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/medium-zoom@1/dist/medium-zoom.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/velocity-animate@1/velocity.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/velocity-animate@1/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.getAttribute('pjax') !== null) {
      script.setAttribute('pjax', '');
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : '9bBjpz3HRuKNuKNp7T27dFsT-gzGzoHsz',
      appKey     : 'k2pzqGWjkjrKxlFLQ3O0oqDn',
      placeholder: "Just go go",
      avatar     : 'robohash',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

    </div>
</body>
</html>
